#! /bin/sh
#
# Fetch rules and targets prior for the "big-js" benchmark.
#
# Uses sh because bash is not installed within the semgrep docker container.
#
set -eu

mkdir -p input

# This was the slowest rule on the Figma codebase
cp semgrep_slow.yml input/semgrep.yml
# Nathan optimized it recently (in semgrep_fast.yml) but it's better
# to try to optimize also the older slower version.

cd input

# Obtain a shallow clone of a git repo for a specific commit
shallow_clone() {
  if [ -d "$name" ]; then
    echo "Reusing repo '$name'"
  else
    echo "Obtaining a shallow clone of git repo '$name', commit $commit"
    mkdir -p "$name"
    (
      cd "$name"
      git init
      git remote add origin "$url"
      git fetch --depth 1 origin "$commit"
      git checkout FETCH_HEAD -b tmp
    )
  fi
}

# Obtain semgrep rules and targets
name="big-js"
#TODO: the other repo are using https: but this repo is currently private
# so I use ssh
url="git@github.com:returntocorp/big-js.git"
commit="08ba212ac7961768fcde386f70eea7a901ddb8f5"
shallow_clone
